<?php
require_once('../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/local/blackboxsurvey/forms.php");
define('AJAX_SCRIPT', true);

//yeu cau login,sau khi login tu dong chuyen sang trang chu
global $USER;
if ($USER->id == null){
    $SESSION->homepage = true;
    require_login($SITE);
}
if($SESSION->homepage){
    $SESSION->homepage = null;
    redirect( $CFG->wwwroot);
}

//object class
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questions.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/question_choice.php");

$id = required_param('id', PARAM_TEXT);

/* Viet doan code cua ban o day */

//get question detail
$b_ques = new b_questions();
$question = $b_ques->get_question_detail($id);

//add question to array to show
$ques_detail['id'] = $question->id;
$ques_detail['content'] = $question->content;
$ques_detail['type'] = $question->id_type;
//echo "<script>alert('".$ques_detail['content']."');</script>";
//lay option cua cau hoi neu co
if($ques_detail['type'] == 2 || $ques_detail['type'] == 3)
{
    //echo "<script>alert('".$ques_detail['type']."');</script>";
    //get option of question
    //echo "<script>alert('".$id."');</script>";
    $b_ques_choice = new b_question_choice();
    $choice = $b_ques_choice->get_choice_by_question($id);
    
    $ques_detail['num_opt'] = count($choice);
    
    $index = 1;
    //add option to array to show
    foreach($choice as $r) {
        $ques_detail['opt_id'.$index] = $r->id;
        $ques_detail['opt_ct'.$index] = $r->content;
        $index++;
    }
    
}
//array('id'=>$type_id,'path_image'=>$path_image)
$mform = new form_view_short_question(null, $ques_detail);

if ($fromform = $mform->get_data()) 
{	
	//close colorbox
	echo "<script>parent.$.fn.colorbox.close(); </script>";
}

$mform->display();
/*------Ket thuc doan code cua ban-------*/

